<%@page pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
	<head>
		<meta http-equiv=Content-Type content="text/html; charset=utf-8" />
		<link href="css/main/style.css"
			type="text/css" rel="stylesheet" />
<script type="text/javascript">
	// 定义了XMLHttpRequest对象
	var xmlrequest;
	// 完成XMLHttpRequest对象的初始化
	function createXMLHttpRequest()
	{
		if(window.XMLHttpRequest)
		{ 
			// DOM 2浏览器
			xmlrequest = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			// IE浏览器
			try
			{
				xmlrequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlrequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
				}
			}
		}
	}
	// 事件处理函数，当下拉列表选择改变时，触发该事件
	function submitIt(index)
	{
		var xh = document.getElementsByName("xh");
		var xinghao = xh[index].innerText;
		
		var bj = document.getElementsByName("bj");
		var baojia = bj[index].innerText;
		
		// 初始化XMLHttpRequest对象
		createXMLHttpRequest();
		// 设置请求响应的URL
		var uri = "carservlet?xinghao=" + xinghao +"&baojia=" + baojia;
		// 打开与服务器响应地址的连接
		xmlrequest.open("GET", uri, true);
		// 设置请求头
		xmlrequest.setRequestHeader("Content-Type"
		, "application/x-www-form-urlencoded");
		// 设置处理响应的回调函数
		xmlrequest.onreadystatechange = processResponse;
		// 发送请求
		xmlrequest.send(null);
	}
	// 定义处理响应的回调函数
	function processResponse()
	{
		// 响应完成且响应正常
		if (xmlrequest.readyState == 4)
		{
			if (xmlrequest.status == 200)
			{
				var f = xmlrequest.getResponseHeader("fmessage");
				if(f==1){
					alert("该物品已经放在购物车了");
				}else{
					alert("加入购物车成功");
				}
			}
			else
			{
				// 页面不正常
				window.alert("您所请求的页面有异常。");
			}
		}
	}
</script>
	</head>
	<body topMargin="10">
		<div id="append_parent"></div>
		<table cellSpacing=6 cellPadding=2 width="100%" border="0">
			<tbody>
				<tr>
					<td>
						<table class="guide" cellSpacing="0" cellPadding="0" width="100%"
							border="0">
							<tbody>
								<tr>
									<td>
										<a href='#'>主页</a>&nbsp;/&nbsp;
										<a href='#'>笔记本订购(WEB007)</a>&nbsp;/&nbsp;商品列表
									</td>
								</tr>
							</tbody>
						</table>
						<br />

						<table class="tableborder" cellSpacing="0" cellPadding="0"
							width="100%" border="0">
							<tbody>
								<tr class="header">
									<td class="altbg1" width="15%">
										<b>型号</B>
									</td>
									<td class="altbg1" width="20%">
										<b>产品图片</b>
									</td>
									<td class="altbg1" width="30%">
										<b>产品说明</b>
									</td>

									<td class="altbg1" width="10%">
										<b>产品报价</b>
									</td>
									<td class="altbg1">&quot;
									</td>
								</tr>
							</tbody>
							<c:forEach items="${list}" var="gs" varStatus="status">
									<tr>
										<td name="xh">${gs.xh}</td>
										<td><img src="${gs.psrc}" width="100px"/></td>
										<td>${gs.shm}</td>
										<td name="bj">${gs.bj}</td>
										<td><a href="#" onclick="submitIt(${status.index})">加入购物车</a></td>
									</tr>
							</c:forEach>
						</table>
						<br />
						<center>
						<form action="msgservlet" method="post">
							<input class="button" type="submit" value="查看购物车"
								name="settingsubmit">
						</form>
						</center>
					</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>